<template>
  <div class="login-container">
    <div class="login-box">
      <div class="logo-wrapper">
        <img src="@/assets/favicon.svg" alt="logo" class="login-logo" />
      </div>
      <h2>批发云仓管家</h2>
      <p class="login-desc">欢迎回来，请登录您的账户</p>

      <el-form ref="form" :model="loginForm" label-width="80px" @submit.prevent="submitForm">
        <el-form-item label="用户名">
          <el-input v-model="loginForm.username" prefix-icon="User" />
        </el-form-item>

        <el-form-item label="密码">
          <el-input v-model="loginForm.password" type="password" show-password prefix-icon="Lock" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" native-type="submit" block>登 录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>


<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import request from '@/utils/request'
import { useUserStore } from '@/stores/userStore'
import { ElMessage } from 'element-plus'

const router = useRouter()
const userStore = useUserStore()

const loginForm = ref({
  username: '',
  password: ''
})

const submitForm = async () => {
  try {
    const res = await request.post('/employee/login/', loginForm.value)
    userStore.setToken(res.token)
    userStore.setUserInfo(res)
    router.push('/')
  } catch (error) {
    console.error('登录失败:', error)
  }
}
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: linear-gradient(135deg, #1890ff 0%, #36cfc9 100%);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  position: relative;
  overflow: hidden;
}

.login-container::before {
  content: '';
  position: absolute;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 60%);
  animation: rotate 20s linear infinite;
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.login-box {
  width: 420px;
  padding: 40px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
  text-align: center;
  position: relative;
  z-index: 1;
}

.logo-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 20px;
}

.login-logo {
  width: 80px;
  height: 80px;
  transition: transform 0.3s ease;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
}

.login-logo:hover {
  transform: scale(1.05) rotate(5deg);
}

.login-box h2 {
  margin: 0 0 10px;
  color: #1a1a1a;
  font-weight: 600;
  font-size: 24px;
  letter-spacing: 1px;
  background: linear-gradient(45deg, #1890ff, #36cfc9);
  -webkit-background-clip: text;
  color: transparent;
}

.login-desc {
  text-align: center;
  color: #666;
  margin-bottom: 30px;
  font-size: 14px;
  font-weight: 500;
}

.el-form {
  width: 100%;
}

:deep(.el-form-item__label) {
  font-weight: 500;
  color: #333;
}

:deep(.el-input__wrapper) {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05) !important;
  border-radius: 8px;
  transition: all 0.3s ease;
}

:deep(.el-input__wrapper:hover) {
  box-shadow: 0 4px 12px rgba(24, 144, 255, 0.1) !important;
}

:deep(.el-input__wrapper.is-focus) {
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2) !important;
}

:deep(.el-button--primary) {
  width: 100%;
  height: 44px;
  font-weight: 500;
  font-size: 16px;
  border-radius: 8px;
  background: linear-gradient(45deg, #1890ff, #36cfc9);
  border: none;
  transition: all 0.3s ease;
}

:deep(.el-button--primary:hover) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(24, 144, 255, 0.3);
}

:deep(.el-button--primary:active) {
  transform: translateY(0);
}

.login-box:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
}

:deep(.el-input__inner) {
  height: 44px;
}

:deep(.el-form-item) {
  margin-bottom: 24px;
}
</style>


